import { listPostByPageUsingPOST } from '../../services/lmxapibackend/interfanceInfoController';
import { PageContainer } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { List, theme } from 'antd';
import React, { useEffect, useState } from 'react';

import { history } from 'umi';
/**
 * 每个单独的卡片，为了复用样式抽成了组件
 * @param param0
 * @returns
 */

const Index: React.FC = () => {
  const { token } = theme.useToken();
  const { initialState } = useModel('@@initialState');
  const [list, setInterfanceList] = useState<API.InterfanceInfo[]>();
  const [total, setTotal] = useState<number>(0);
  const [current, setCurrent] = useState<number>(1);
  const size = 20; // 每页显示的页数
  // 首次加载页面的是否分页查询数据
  //
  const getPageInterfanceLisr = async (current: number = 1) => {
    let res = await listPostByPageUsingPOST({
      current: current,
      pageSize: size,
      status: 1,
    });
    if (res.code === 0 && res.data != null) {
      setInterfanceList(res.data.records);
      setTotal(res?.data?.total ?? 0);
      // setCurrent(res?.data?.current ?? 1);
    }
    console.log(res);
  };
  useEffect(() => {
    getPageInterfanceLisr(current);
  }, []);

  return (
    <PageContainer title={'Lm在线接口开放平台'}>
      <List
        itemLayout="horizontal"
        dataSource={list}
        renderItem={(item) => (
          <List.Item>
            <List.Item.Meta title={<a onClick={() => {
                history.push('/interfanceinfo/'+item.id);
              }}>{item.name}</a>}
              description={item.decprition}
            />
          </List.Item>
        )}
        pagination={{
          pageSize: size,
          // current: current,
          total: total,
          showTotal: (total) => ` 共${total}`,
          onChange: (currnet) => {
            console.log(currnet);
            getPageInterfanceLisr(currnet);
          },
        }}
      />
      {/*  <Pagination*/}
      {/*    simple*/}
      {/*    current={current}*/}
      {/*    onChange={async () => {*/}
      {/*      console.log('inchange');*/}
      {/*      setCurrent(current);*/}
      {/*      await getPageInterfanceLisr();*/}
      {/*    }}*/}
      {/*    total={total}*/}
      {/*  />*/}
    </PageContainer>
  );
};

export default Index;
